
<div class="sectionY">
    <a href="javascript:void(0);" onclick="window.history.go(-1);">
        <img src="__STATIC__/wechat/images/a1.png" class="a1" alt="">
    </a>
    <p class="p1">确认订单</p>
</div>
<div class="kong1"></div>
<div class="ding_section1">
    <div class="container">

        <div class="ding1 clearfix" id="addbtn">
            <a href="javascript:void(0);">
                <div class="a1">
                    <img src="__STATIC__/wechat/images/a20.png" alt="">
                </div>
                <div class="a2">
                    <p class="p1" id="show-add1">{$info.address.name|default='编辑收货地址'} {$info.address.mobile}</p>
                    <p class="p2 chao" id="show-add2">{$info.address.address}</p>
                </div>
                <div class="a3">
                    <img src="__STATIC__/wechat/images/a6.png" alt="">
                </div>
            </a>
        </div>
        <div class="ding2">
            <div class="a1">
                <img src="{$info.business.img_url}" alt="">
                <span class="s1">{$info.business.title}</span>
            </div>
            {volist name="$info['goods']" id="item"}
            <div class="a2 clearfix">
                <div class="z1">
                    <img src="{$item.img_url}" alt="">
                </div>
                <div class="z2">
                    <p class="p1 chao">{$item.title}</p>
                    <p style="color: grey;font-size: 0.8rem;" class="p1 chao">{$item.spec_title}</p>
                    <div class="e1 clearfix">
                        <span class="s1">￥{$item.price}</span>
                        <span class="s2">x{$item.num}</span>
                    </div>
                </div>
            </div>
            {/volist}
        </div>
        <div class="ding3">
            <div id="yf" class="a1 clearfix">
                <p class="p1">运费</p>
                <p class="p2"><span class="s1">{$info.dispatch_price}</span><img src="__STATIC__/wechat/images/a6.png" alt=""></p>
            </div>
            <div class="a2 clearfix">
                <div class="z1">
                    <p class="p1">留言</p>
                </div>
                <div class="z2">
                    <input maxlength="200" id="message" type="text" placeholder="请输入留言">
                    <p class="p1">共<span class="s1">{$info.goods_total}</span>件商品，小计<span class="s1"> ￥{$info.goods_price} </span>元</p>
                </div>
            </div>

            {if $info['can_use_coin']}
            <div class="a3 clearfix">
                <p class="p1">商基因</p>
                <p class="p2">当前可用商基因<span class="s1">{$info.use_coin}</span>，抵扣<span class="s1">￥{$info.coin_money}</span></p>
                <p id="uny" class="p3">
                    <img class="un" src="__STATIC__/wechat/images/switch_off.png" alt="">
                    <img class="uy" src="__STATIC__/wechat/images/switch_on.png" alt="" style="display: none;">
                </p>
            </div>
            {/if}
        </div>
    </div>
</div>
<div class="kong"></div>
<div class="foot_buy">
    <div class="a1">
        <span id="pricc" class="s1">￥{$info.no_use_coin_price}</span>
    </div>
    <div class="a2">
        <span id="confirmbtn" class="s1">确认订单</span>
    </div>
</div>
<div class="yunfei">
    <div class="yufei-nei">
        <div class="yufei-di">
            <p class="p1">运费详情</p>
            <div class="yufei-h">
                {volist name="$info['dispatch_detail']" id="item"}
                <p class="p2">
                    <span>{$item.title}</span>
                    <a href="javascript:void(0);">{$item.price}</a>
                </p>
                {/volist}
            </div>
            <p class="p3">确认</p>
        </div>
    </div>
</div>
<div id="addbor" class="addbor">
    <div style="width:90%;margin:0 auto;margin-top:15%;border-radius:5px;background: #fff;padding:0 0 5% 0;">
        <p style="line-height: 35px;text-align: center" >编辑地址</p>
        <div class="add_dizhi">

                <div class="f1 clearfix">
                    <span class="s1">联系人</span>
                    <input type="text" placeholder="收货人姓名" id="add-name" value="{$info.address.name}" class="input1">
                </div>
                <div class="f1 clearfix">
                    <span class="s1">手机号</span>
                    <input type="text" placeholder="手机号" id="add-mobile"  value="{$info.address.mobile}" class="input1">
                </div>
                <div class="f1 clearfix" >
                    <span style="width: 30%" class="s1">所在地区</span>
                    <span id="add-area" style="width: 68%;margin-left: 2%" class="s1">{$info.address.area|default="点击选择地区"}</span>
                </div>
                <div class="f1 clearfix">
                    <input type="text" placeholder="详细地址" value="{$info.address.add}" id="add-add" class="input2">
                </div>
                <!--<div class="ge"></div>-->
                <!--<div class="f2 clearfix">-->
                    <!--<span class="s2">设为默认地址</span>-->
                    <!--<img src="__STATIC__/wechat/images/switch_on.png" alt="" class="im1 ud1">-->
                    <!--<img src="__STATIC__/wechat/images/switch_off.png" alt="" class="im1 ud2">-->
                <!--</div>-->
                <div class="sub">
                    <input style="-webkit-appearance:none;" id="add-btn" type="submit" value="保存">
                </div>


        </div>
    </div>

</div>
<input type="hidden" id="id" value="{$id}">
<input type="hidden" id="spec_id" value="{$spec_id}">
<input type="hidden" id="num" value="{$num}">
<input type="hidden" id="group_id" value="{$group_id}">
<input type="hidden" id="type" value="{$type}">
<input type="hidden" id="name" value="{$info.address.name}">
<input type="hidden" id="mobile" value="{$info.address.mobile}">
<input type="hidden" id="address" value="{$info.address.address}">
<input type="hidden" id="use_coin" value="0">
<script type="text/javascript" src="__STATIC__/wechat/js/city.js"></script>
<link rel="stylesheet" type="text/css" href="__STATIC__/wechat/select/css/mobileSelect.css">
<script src="__STATIC__/wechat/select/js/mobileSelect.js" type="text/javascript"></script>
<script type="text/javascript">
    var mobileSelect4 = new MobileSelect({
        trigger: '#add-area',
        title: '收货地址',
        wheels: [
            {data:cityJson}
        ],
        transitionEnd:function(indexArr, data){
            //console.log(data);
        },
        callback:function(indexArr, data){
            //console.log(data);
        }
    });
    $("#addbtn").click(function () {
        $("#addbor").show();
    });
    $("#add-btn").click(function () {
        var aname = $("#add-name").val();
        var amobile = $("#add-mobile").val();
        var aarea = $("#add-area").html();
        var aadd = $("#add-add").val();
        if(aname==''){
            $.Toast('提示','请输入收货人姓名','warning');
            return false;
        }
        if(amobile==''){
            $.Toast('提示','请输入收货人手机号码','warning');
            return false;
        }
        {php}$pregRule=config('tel_regular');{/php}
        var preg = {$pregRule};
        if(!preg.test(amobile)){
            $.Toast('提示','手机号码有误！','warning');
            return false;
        }
        if(aarea==''||aarea=='点击选择地区'){
            $.Toast('提示','请选择收货地址','warning');
            return false;
        }
        if(aadd==''){
            $.Toast('提示','请输入详细地址','warning');
            return false;
        }
        $("#show-add1").html(aname+' '+amobile);
        $("#show-add2").html(aarea+' '+aadd);
        $("#name").val(aname);
        $("#mobile").val(amobile);
        $("#address").val(aarea+' '+aadd);
        $("#addbor").hide();
    });
    $("#yf").click(function () {
        $(".yunfei").show();
    });
    $(".yufei-di .p3").click(function () {
        $(".yunfei").hide();
    });
    $("#uny").click(function () {
        var np = "{$info.no_use_coin_price}";
        var yp = "{$info.use_coin_price}";
        var use = $("#use_coin").val();
        if(use==1){
            $(".uy").hide();
            $(".un").show();
            $("#use_coin").val(0);
            $("#pricc").html('￥'+np);
        }else{
            $(".uy").show();
            $(".un").hide();
            $("#use_coin").val(1);
            $("#pricc").html('￥'+yp);
        }
    });
    //提交
    $("#confirmbtn").click(function () {
        if($("#confirmbtn").hasClass('sending')){
            $.Toast('提示','订单提交中请稍候','warning');
            return false;
        }
        var id = $("#id").val();
        var spec_id = $("#spec_id").val();
        var num = $("#num").val();
        var group_id = $("#group_id").val();
        var type = $("#type").val();
        var name = $("#name").val();
        var mobile = $("#mobile").val();
        var address = $("#address").val();
        var message = $("#message").val();
        var use_coin = $("#use_coin").val();
        $.ajax({
            type:'post',
            url:"{:url('')}",
            data:{id:id,spec_id:spec_id,num:num,group_id:group_id,type:type,name:name,mobile:mobile,address:address,message:message,use_coin:use_coin},
            cache:false,
            dataType:'JSON',
            success:function(data){
                $("#confirmbtn").removeClass('sending');
                if(data.status==0){
                   if(data.data.need_pay == 0){
                       //支付成功
                       $.Toast("提示","订单支付成功，下载APP可以查看订单记录","success");
                       setTimeout(function () {
                           window.location.href = "{:url('Utils/down')}";
                       },2500);
                   }else{
                        //微信jsapi支付
                       WeixinJSBridge.invoke(
                           'getBrandWCPayRequest',data.data.wx,
                           function(res){
                               if(res.err_msg == "get_brand_wcpay_request:ok" ){
                                   $.Toast("提示","订单支付成功，下载APP可以查看订单记录","success");
                                   setTimeout(function () {
                                       window.location.href = "{:url('Utils/down')}";
                                   },2500);
                               }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                                   $.Toast("提示","支付已取消","warning");
                               }else if(res.err_msg == "get_brand_wcpay_request:fail"){
                                   $.Toast("提示","支付失败，请重试","error");
                               }else{
                                   $.Toast("提示",res.err_msg,"error");
                               }
                           }
                       );
                   }
                }else{
                    $.Toast('提示',data.info,'error');
                }
            },
            error:function(e){
                $("#confirmbtn").removeClass('sending');
            },
            beforeSend:function(e){
                $("#confirmbtn").addClass('sending');
            }
        });


    });
</script>